package com.tang.controller;

import com.tang.config.SecurityConfig;
import com.tang.pojo.Books;
import com.tang.pojo.User;
import com.tang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author Tom
 * @ClassName LoginController
 * @Date 2022/2 21:00
 */
 @Controller
public class LoginController {
     @Autowired
     private UserService userService;
@GetMapping("/login.html")
public String login(){

    return "login";
}
    //跳转用户添加页
    @RequestMapping("/addUser")
    public String addUser(Model model) {

        return "addUser";
    }

    //添加书籍后,重定向到首页
    @RequestMapping("/addUserSuccess")
    public String addSuccess(User user, HttpServletRequest request) {
        System.out.println("成功添加" + user);
        userService.addUser(user);
//        redisTemplate.opsForValue().set("book",books);

        return "redirect:index";
    }
////自定义失败页面
//@RequestMapping("/errno")
//public String erron(){
//    return "erro/403";
//}
}
    